home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / gnulib / RCS / gnulib3.c,v < prev    next >
Encoding:
Text File  |  1990-06-27  |  2.2 KB  |  153 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     90.06.26.19.00.51;  author rab;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     90.04.13.11.10.38;  author rab;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @Fixed ON_EXIT macro to work correctly for sprite.
  27. @
  28. text
  29. @typedef struct set_vector
  30. {
  31.   int length;
  32.   int vector[1];
  33.   /* struct set_vector *next; */
  34. } set_vector;
  35.  
  36. #ifdef sprite
  37. set_vector __CTOR_LIST__;
  38. set_vector __DTOR_LIST__;
  39. static set_vector *__dlp;
  40. static int __dli;
  41. int __1xyzzy__;
  42. #else
  43. extern set_vector __CTOR_LIST__;
  44. extern set_vector __DTOR_LIST__;
  45. set_vector *__dlp;
  46. int __dli;
  47. #endif
  48.  
  49. extern void exit ();
  50. extern void __do_global_init ();
  51. extern void __do_global_cleanup ();
  52. extern void on_exit(void*, void*);
  53.  
  54. #if defined(i386) && !defined(sequent)
  55. #define COFF
  56. #endif
  57.  
  58. #ifdef COFF_ENCAPSULATE
  59. #undef COFF
  60. #endif
  61.  
  62. #if defined(sprite)
  63. #define ON_EXIT(PROCP) \
  64.   do { extern void PROCP (); atexit (PROCP); } while (0)
  65. #endif
  66.  
  67. int
  68. __main ()
  69. {
  70.   /* Gross hack for GNU ld.  This is defined in `builtin.cc'
  71.      from libg++.  */
  72. #ifndef COFF
  73.   extern int __1xyzzy__;
  74. #endif
  75.  
  76. #ifdef ON_EXIT
  77.  
  78. #ifdef sprite
  79.   ON_EXIT (_cleanup);
  80. #endif
  81.  
  82.   ON_EXIT (__do_global_cleanup);
  83.  
  84. #endif
  85.   __dli = __DTOR_LIST__.length;
  86.   __dlp = &__DTOR_LIST__;
  87. #ifndef COFF
  88.   __do_global_init (&__1xyzzy__);
  89. #else
  90.   __do_global_init ();
  91. #endif
  92. }
  93.  
  94. #ifndef ON_EXIT
  95. void 
  96. exit (status)
  97.      int status;
  98. {
  99.   __do_global_cleanup ();
  100.   _cleanup ();
  101.   _exit (status);
  102. }
  103. #endif
  104.  
  105. void
  106. __do_global_init ()
  107. {
  108.   register int i, len;
  109.   register void (**ppf)() = (void (**)())__CTOR_LIST__.vector;
  110.  
  111.   len = __CTOR_LIST__.length;
  112.   for (i = 0; i < len; i++)
  113.     (*ppf[i])();
  114. }
  115.  
  116. void
  117. __do_global_cleanup ()
  118. {
  119.   while (__dlp)
  120.     {
  121.       while (--__dli >= 0)
  122.     {
  123.       void (*pf)() = (void (*)())__dlp->vector[__dli];
  124.       (*pf)();
  125.     }
  126.       __dlp = (struct set_vector *)__dlp->vector[__dlp->length];
  127.       if (__dlp) __dli = __dlp->length;
  128.     }
  129. }
  130. @
  131.  
  132.  
  133. 1.1
  134. log
  135. @Initial revision
  136. @
  137. text
  138. @d8 7
  139. d19 1
  140. d34 3
  141. a36 3
  142. #if defined(sun)
  143. #define ON_EXIT(PROCP, ARG) \
  144.   do { extern void PROCP (); on_exit (PROCP, ARG); } while (0)
  145. d50 2
  146. a51 2
  147. #ifdef sun
  148.   ON_EXIT (_cleanup, 0);
  149. d54 1
  150. a54 1
  151.   ON_EXIT (__do_global_cleanup, 0);
  152. @
  153.